import request from "@/server/instanceAxios.ts";

interface LoginProp {
  username?: string;
  password?: string | number | any;
}

export interface DoActionProp {
  instId: string | number;
  sId: string | number;
  defKey: string | number;
  id: string | number;
  formGuid: string | undefined | unknown;
  defId: string | number;
  taskId: string | number;
  instanceId: string | number;
  formType: "FRAME";
  action: "agree" | "reject";
  nodeId: string;
  data: {
    test: "jeff";
  };
  test: "jeff";
  businessKey: string;
  destination: string;
  nodeUsers: {
    [key: string]: any;
  };
}

export function login(data: LoginProp) {
  return request({
    url: "/dingTalk/dingLogin",
    method: "post",
    data,
  });
}

export function getName(data: { username: string | number }) {
  return request({
    url: "/getName",
    method: "post",
    data,
  });
}

export function mockUrl(): Promise<any> {
  return new Promise((resolve) => {
    const url =
      "http://115.239.175.246:3028/dist/#/commonProgressPage?subject=陈杰在2020-08-10发起以前年度财政支出退回&title=以前年度财政支出退回&sId=zjsrTable&bizKey=2020081000015545&defId=417975798335012865&instId=418651569811095553&flag=1&fileType=017&nsukey=979Wcb7lw3dJkvsjhn2a%2FRutFPSJiEp7mrfC%2F4UBL9s4DBcDbwUSdSo4dxUUu3l5GRQE6D4r9HG5VJYlXvCnbHik0TgA1YIsh1Grm6GSynKRTUNTthA5RSKqSHd4hUiT98yqsxxdmiPS5A%2ByCmU1MveLy6fKbW06qsrjEvdm2WYp9YPu4QMlEPdBVv0jSmK4iVq4Gxkp%2B60oYmu%2F5OjbTA%3D%3D";
    resolve(url);
  });
}

export function taskFindFormGuid(
  url: string,
  data: { formGuid: string | number }
) {
  return request({
    url: `${url}`,
    method: "post",
    data,
  });
}

export function getInstanceOpinion(data: { instId: string }) {
  return request({
    url: `/formTask/instance/getInstanceOpinion`,
    method: "get",
    params: data,
  });
}

export function taskDoAction(data: DoActionProp) {
  return request({
    url: `/formTask/doAction`,
    method: "post",
    data,
  });
}

export function modifyStatus(
  url: string,
  data: { formGuid: string | number; status: "-1" }
) {
  return request({
    url: `/${url}/status`,
    method: "post",
    data,
  });
}

export function queryHeader(data: { tableId: number | string }) {
  return request({
    url: `/adminAnalysis/query/header`,
    method: "post",
    data,
  });
}

export function formTaskList(
  url: string,
  data: { limit: number | string; offset: number | string; order: "asc" }
) {
  return request({
    url: `/formTask/my/${url}`,
    method: "post",
    data,
  });
}

export function getSidByDefKey(data: { key: string }) {
  return request({
    url: `/menu/getSidByDefKey`,
    method: "post",
    data,
  });
}

export function haveMobileToken(data: { telephone: string }) {
  return request({
    url: `/getToken`,
    method: "post",
    data,
  });
}

export function handleNodeFreeUser(data: {
  action: string;
  businessKey: string;
  data: {
    [key: string]: any;
  };
  defId: string | number;
  extendConf: {
    nodeId: string;
    [key: string]: any;
  };
  taskId: string;
  nodeId: string;
}) {
  return request({
    url: `/formTask/task/handleNodeFreeSelectUser`,
    method: "post",
    data,
  });
}

export function getCanBackHistoryNodes(data: { taskId: string | number }) {
  return request({
    url: `/formTask/task/getCanBackHistoryNodes`,
    method: "post",
    data,
  });
}

export function filePage(data: {
  guid: string | number;
  status: string | "";
  type: string | number;
}) {
  return request({
    url: "/file/page",
    method: "post",
    data,
  });
}
